package com.android.djlmapp.adapter.order;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.android.djlmapp.R;
import com.android.djlmapp.model.order.OrderListInfo;
import com.android.djlmapp.tools.global.BigDecimalUtils;
import com.android.djlmapp.tools.global.ToastUtils;
import com.bumptech.glide.Glide;

import org.refresh_view.pullrecyclerview.BaseViewHolder;

import static com.android.djlmapp.fragment.ChildOrderFragment.BROADBAND_ORDER_TYPE;
import static com.android.djlmapp.fragment.ChildOrderFragment.FLOW_CHARGE_ORDER_TYPE;
import static com.android.djlmapp.fragment.ChildOrderFragment.GAME_CHARGE_ORDER_TYPE;
import static com.android.djlmapp.fragment.ChildOrderFragment.KAIKA_ORDER_TYPE;
import static com.android.djlmapp.fragment.ChildOrderFragment.Q_MONEY_CHARGE_ORDER_TYPE;
import static com.android.djlmapp.fragment.ChildOrderFragment.TEL_CHARGE_ORDER_TYPE;
import static com.android.djlmapp.fragment.ChildOrderFragment.TERMINAL_ORDER_TYPE;

/**
 * @Author wangziheng
 * @ProjectName djlm
 * @ClassName AllOrderListAdapter
 * @package com.android.djlmapp.adapter.order
 * @data 2019/1/24 18:57
 * @Describe
 * @Change
 */
public class AllOrderListAdapter extends OrderListAdapter {
    public AllOrderListAdapter(Context context) {
        super(context);
    }

    @Override
    protected void convert(BaseViewHolder holder, OrderListInfo.DataBean item) {
        super.convert(holder, item);
        if(TextUtils.isEmpty(item.getOrder_type())){
            // 服务端全部订单选项  订单类型为空
            ToastUtils.showShortToast(holder.getView().getContext(),"服务端数据异常");
            return;
        }
        int orderType = Integer.valueOf(item.getOrder_type());
        mOrderNameTv.setTextColor(holder.itemView.getContext().getResources().getColor(R.color.black));
        switch (orderType){
            case KAIKA_ORDER_TYPE:
                // 开卡订单

                String kkPhonenum = item.getPhone();
                kkPhonenum = separateString(kkPhonenum, 3, 4, ' ');
                mOrderNameTv.setText(kkPhonenum);

                String infoMoney = item.getInto_money();
                if(TextUtils.isEmpty(infoMoney)){
                    infoMoney = "0";
                }
                String packageMoney = item.getVirtual_package_money();
                if(TextUtils.isEmpty(packageMoney))
                {
                    packageMoney = "0";
                }
                String phoneMoney = item.getVirtual_phonenum_money();
                if(TextUtils.isEmpty(phoneMoney)){
                    phoneMoney = "0";
                }
                String price = BigDecimalUtils.add(2,infoMoney,packageMoney,phoneMoney);
                holder.setText(R.id.order_list_orderPrice_tv,"¥:  " + price);
                holder.setImageResource(R.id.order_list_goodsIcon_img,R.mipmap.order_kk_icon);
                break;
            case TEL_CHARGE_ORDER_TYPE:
                // 话费充值订单
                String TelPhonenum = item.getPhonenum();
                TelPhonenum = separateString(TelPhonenum, 3, 4, ' ');
                mOrderNameTv.setText(TelPhonenum);
                holder.setText(R.id.order_list_orderPrice_tv,"¥:  " + item.getFace_price());
                holder.setImageResource(R.id.order_list_goodsIcon_img,R.mipmap.order_tel_charge_icon);

                break;
            case FLOW_CHARGE_ORDER_TYPE:

                // 流量充值订单
                String flowOrderPhonenum = item.getPhonenum();
                flowOrderPhonenum = separateString(flowOrderPhonenum, 3, 4, ' ');
                mOrderNameTv.setText(flowOrderPhonenum);
                holder.setText(R.id.order_list_orderPrice_tv,"¥:  " + item.getMarket_price());
                holder.setImageResource(R.id.order_list_goodsIcon_img,R.mipmap.order_flow_icon);

                break;
            case BROADBAND_ORDER_TYPE:
                // 宽带订单
                mOrderNameTv.setText(item.getName_type());
                holder.setText(R.id.order_list_orderPrice_tv,"¥:  " + item.getOrder_money());
                holder.setImageResource(R.id.order_list_goodsIcon_img,R.mipmap.order_bb_icon);

                break;
            case TERMINAL_ORDER_TYPE:
                // 终端订单
                mOrderNameTv.setText(item.getModel());
                holder.setText(R.id.order_list_orderPrice_tv,"¥:  " + item.getExpress_price());
                ImageView terminalImg = holder.itemView.findViewById(R.id.order_list_goodsIcon_img);
                Glide.with(terminalImg).load(item.getImage()).into(terminalImg);

                break;
            case Q_MONEY_CHARGE_ORDER_TYPE:
                // Q币充值订单
                mOrderNameTv.setText(item.getQq_number());
                holder.setText(R.id.order_list_orderPrice_tv,"¥:  " + item.getAll_sale_price());
                holder.setImageResource(R.id.order_list_goodsIcon_img,R.mipmap.order_qq_charge_icon);

                break;
            case GAME_CHARGE_ORDER_TYPE:
                // 游戏充值订单
                mOrderNameTv.setText(item.getAccount());
                holder.setText(R.id.order_list_orderPrice_tv,"¥:  " + item.getAll_sale_price());
                holder.setImageResource(R.id.order_list_goodsIcon_img,R.mipmap.order_qq_charge_icon);

                break;
            default:
                break;
        }
    }

    @Override
    public String[] getOrderStatusValue(String orderStatusCode,String orderType) {
//        Log.i("全部订单", "订单类型: " + mOrderTypeSparseArray.get(ORDER_TYPE[Integer.valueOf(orderType)]) + "  " + orderType);
        return OrderStatusAndType.getOrderStatus(orderStatusCode,orderType);
    }
}
